/*
 * Copyright (C) 2011-2016 Markus Junginger, greenrobot (http://greenrobot.org)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.greenrobot.greendao;

import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * Internal greenDAO logger class. A wrapper around the HiLog class providing a static Log Tag.
 * @author markus
 */
public class DaoLog {
    /**
     * DAO module value as per API doc
     */
    public static final int DAO_MODULE = 0x00201;
    /**
     * Debug log value
     */
    public static final int DEBUG = 3;
    /**
     * Info log value
     */
    public static final int INFO = 4;
    /**
     * warning log value
     */
    public static final int WARN = 5;
    /**
     * error log value
     */
    public static final int ERROR = 6;
    /**
     * Fatal log value
     */
    public static final int FATAL = 7;
    /**
     * Hi log label
     */
    private static final HiLogLabel TAG = new HiLogLabel(HiLog.LOG_APP, DAO_MODULE, "greenDAO");

    /**
     * check if the mentioned level is loggable
     * @param level log level
     * @return is loggable or not
     */
    public static boolean isLoggable(int level) {
        return HiLog.isLoggable(DAO_MODULE, "greenDAO", level);
    }

    /**
     * Get the stack trace
     * @param th throwable to get the stack trace
     * @return stack trace string
     */
    public static String getStackTraceString(Throwable th) {
        return HiLog.getStackTrace(th);
    }

    /**
     * print the log with the log level and message
     * @param level log level
     * @param msg message
     * @return log printed or not
     */
    public static int println(int level, String msg) {
        return HiLog.debug(TAG, "LogLevel = " + level + "\n" + msg);
    }

    /**
     * print the verbose log
     * @param msg log message
     * @return log printed or not
     */
    public static int v(String msg) {
        return HiLog.debug(TAG, msg);
    }

    /**
     * print the verbose log with throwable stacktrace
     * @param msg log message
     * @param th throwable trace
     * @return log printed or not
     */
    public static int v(String msg, Throwable th) {
        return HiLog.debug(TAG, msg, th);
    }

    /**
     * print the debug log
     * @param msg log message
     * @return log printed or not
     */
    public static int d(String msg) {
        return HiLog.debug(TAG, msg);
    }

    /**
     * print the debug log with throwable stacktrace
     * @param msg log message
     * @param th throwable trace
     * @return log printed or not
     */
    public static int d(String msg, Throwable th) {
        return HiLog.debug(TAG, msg, th);
    }

    /**
     * print the info log
     * @param msg log message
     * @return log printed or not
     */
    public static int i(String msg) {
        return HiLog.info(TAG, msg);
    }

    /**
     * print the info log with throwable stacktrace
     * @param msg log message
     * @param th throwable trace
     * @return log printed or not
     */
    public static int i(String msg, Throwable th) {
        return HiLog.info(TAG, msg, th);
    }

    /**
     * print the warning log
     * @param msg log message
     * @return log printed or not
     */
    public static int w(String msg) {
        return HiLog.warn(TAG, msg);
    }

    /**
     * print the warning log with throwable stacktrace
     * @param msg log message
     * @param th throwable trace
     * @return log printed or not
     */
    public static int w(String msg, Throwable th) {
        return HiLog.warn(TAG, msg, th);
    }

    /**
     * print the warning log with throwable stacktrace
     * @param th throwable trace
     * @return log printed or not
     */
    public static int w(Throwable th) {
        return HiLog.warn(TAG, null, th);
    }

    /**
     * print the error log
     * @param msg log message
     * @return log printed or not
     */
    public static int e(String msg) {
        return HiLog.warn(TAG, msg);
    }

    /**
     * print the error log with throwable stacktrace
     * @param msg log message
     * @param th throwable trace
     * @return log printed or not
     */
    public static int e(String msg, Throwable th) {
        return HiLog.error(TAG, msg, th);
    }

}
